package Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.UnknownHostException;

import SecureUtil.UDPHelper;

public class UDPHelperTestClient {
	
	public InetAddress ip;
	public int port = 1234;
	
	public static void main(String[]args){
		UDPHelperTestClient testClient = new UDPHelperTestClient();
		
		try {
			testClient.ip = InetAddress.getLocalHost();
			InputStreamReader isr = new InputStreamReader(System.in) ;
			BufferedReader br = new BufferedReader(isr);
			DatagramSocket _clientSocket = new DatagramSocket();
			
			while(true){
				
				String message = "";
				message = br.readLine();
				//System.out.println(message);
				
				UDPHelper udphelper = new UDPHelper(_clientSocket);
				
				udphelper.sendBytes(message.getBytes(), InetAddress.getLocalHost(), 51620);
				
				byte [] received = udphelper.receiveBytes(0);
				System.out.println(new String(received));
			}
			
			
			
			
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}
